package com.tz.cartelo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.tz.cartelo.R;
import com.tz.cartelo.model.GoodsPictureTail;
import com.tz.cartelo.model.InformationDetails;
import com.tz.cartelo.util.CommonUtils;

import java.util.List;


/**
 * Created by ok on 2016/9/18.
 */
public class MessageAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    private List<InformationDetails> mInformationDetailsList;
    private Context mContext;
    private int mImgWidth, mImgHeight;

    public MessageAdapter(Context context, List<InformationDetails> informationDetailsList) {
        mLayoutInflater = LayoutInflater.from(context);
        mContext = context;
        mInformationDetailsList = informationDetailsList;
//        setImgSize();
    }

    private void setImgSize() {
        mImgWidth = (CommonUtils.getScreenWidth(mContext) - 3 * mContext.getResources().getDimensionPixelOffset(R.dimen.margin_10)) / 2;
        mImgHeight = mImgWidth;
        //+ mContext.getResources().getDimensionPixelOffset(R.dimen.margin_5)
    }

    @Override
    public int getCount() {
        return mInformationDetailsList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
//        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.item_message, null);
            holder = new ViewHolder();
            holder.item_message_title = (TextView) view.findViewById(R.id.item_message_title);
            holder.item_message_content = (TextView) view.findViewById(R.id.item_message_content);
            holder.item_message_view = view.findViewById(R.id.item_message_view);
            view.setTag(holder);
//        } else {
//            holder = (ViewHolder) view.getTag();
//        }
        //1:发货通知，2:系统消息，3，订购通知
        holder.item_message_title.setText(mInformationDetailsList.get(i).getTypeName());
        holder.item_message_content.setText(mInformationDetailsList.get(i).getRemark());
        //0未读  1已读
        if (mInformationDetailsList.get(i).getIsRead().equals("0")){
            holder.item_message_view.setVisibility(View.GONE);
        }else{
            holder.item_message_view.setVisibility(View.VISIBLE);
        }
//        ImageLoader.getInstance().displayImage("drawable://" + R.mipmap.ic_holder_list, holder.itemGoodsDetailsImg, CommonUtils.optionsList());
//        ImageLoader.getInstance().displayImage(mGoodsPictureTailList.get(i).getFileUrl(), holder.itemGoodsDetailsImg, CommonUtils.optionsList());
        return view;
    }

    private class ViewHolder {
        TextView item_message_title;
        TextView item_message_content;
        View item_message_view;
    }

}
